package com.jhd.fuzhou.util;

import android.app.Activity;
import android.content.Context;
import android.graphics.RectF;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

import com.jhd.fuzhou.R;
import com.jhd.fuzhou.util.span.ReplaceSpan;
import com.jhd.fuzhou.util.span.SpansManager;
import com.jhd.fuzhou.vo.GradeQuestionBankVo;

import net.zigin.commons.util.StringUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TextDialog {
    private static AlertDialog _alertDialog=null;
    private static long lastClickTime=0;

    public static void showDialog2(Context context,String title,EditText editText){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000){
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edittext, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            if(_alertDialog.isShowing())_alertDialog.dismiss();
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            if(title.equals("联系电话")){
                String digits="0123456789-";
                et_edit.setKeyListener(DigitsKeyListener.getInstance(digits));
            }else{
                String digits="0123456789";
                et_edit.setKeyListener(DigitsKeyListener.getInstance(digits));
            }
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            et_edit.setText(editText.getText().toString());
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if(!et_edit.getText().toString().equals("")){
                iv_clean.setVisibility(View.VISIBLE);
            }
            if(!StringUtil.isNullOrEmpty(title)){
                tv_title.setText(title);
            }else{
                tv_title.setVisibility(View.GONE);
            }
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if(!s.toString().equals("")){
                        iv_clean.setVisibility(View.VISIBLE);
                    }else{
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String s=et_edit.getText().toString();
                    if(title.equals("联系电话")){
                        if(s.startsWith("1")){
                            if(s.length()!=11){
                                Toast.makeText(context, "手机号长度需为11位!", Toast.LENGTH_SHORT).show();
                            }else{
                                _alertDialog.dismiss();
                                editText.setText(et_edit.getText().toString());
                            }
                        }else if(s.startsWith("0")){
                            if(s.length()<11){
                                Toast.makeText(context, "固话长度不能少于11位!", Toast.LENGTH_SHORT).show();
                            }else{
                                _alertDialog.dismiss();
                                editText.setText(et_edit.getText().toString());
                            }
                        }
                    }else if(title.equals("邮政编码")){
                        if(s.length()!=6){
                            Toast.makeText(context, "邮政编码为6位!", Toast.LENGTH_SHORT).show();
                        }else{
                            _alertDialog.dismiss();
                            editText.setText(et_edit.getText().toString());
                        }
                    }
                }
            });

            WindowManager.LayoutParams params = window.getAttributes() ;
            params.width =(int) (((Activity)context).getWindowManager().getDefaultDisplay().getWidth()*0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }
    public static void showDialog(Context context,String title,EditText editText){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000){
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edittext, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            if(_alertDialog.isShowing())_alertDialog.dismiss();
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            et_edit.setText(editText.getText().toString());
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if(!et_edit.getText().toString().equals("")){
                iv_clean.setVisibility(View.VISIBLE);
            }
            if(!StringUtil.isNullOrEmpty(title)){
                tv_title.setText(title);
            }else{
                tv_title.setVisibility(View.GONE);
            }
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if(!s.toString().equals("")){
                        iv_clean.setVisibility(View.VISIBLE);
                    }else{
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                    editText.setText(et_edit.getText().toString());
                }
            });

            WindowManager.LayoutParams params = window.getAttributes() ;
            params.width =(int) (((Activity)context).getWindowManager().getDefaultDisplay().getWidth()*0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }

    public static void creditCode(Context context,String title,EditText editText){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000){
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edittext, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            if(_alertDialog.isShowing())_alertDialog.dismiss();
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            String digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            et_edit.setKeyListener(DigitsKeyListener.getInstance(digits));
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            et_edit.setText(editText.getText().toString());
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if(!et_edit.getText().toString().equals("")){
                iv_clean.setVisibility(View.VISIBLE);
            }
            if(!StringUtil.isNullOrEmpty(title)){
                tv_title.setText(title);
            }else{
                tv_title.setVisibility(View.GONE);
            }
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if(!s.toString().equals("")){
                        iv_clean.setVisibility(View.VISIBLE);
                    }else{
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(et_edit.getText().toString().length()!=18){
                        CustomToast.showText(context, "社会信用代码必须为18位", 3000, 0, 0).show();
                    }else{
                        _alertDialog.dismiss();
                        editText.setText(et_edit.getText().toString());
                    }
                }
            });

            WindowManager.LayoutParams params = window.getAttributes() ;
            params.width =(int) (((Activity)context).getWindowManager().getDefaultDisplay().getWidth()*0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }
    public static void spanDialog(Context context, String title, EditText editText, int id, ReplaceSpan span, SpansManager spansManager){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000) {
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edittext, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            et_edit.setText(TextUtils.isEmpty(span.mText) ? "" : span.mText);
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if (!et_edit.getText().toString().equals("")) {
                iv_clean.setVisibility(View.VISIBLE);
            }
            if (!StringUtil.isNullOrEmpty(title)) {
                tv_title.setText(title);
            } else {
                tv_title.setVisibility(View.GONE);
            }
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (!s.toString().equals("")) {
                        iv_clean.setVisibility(View.VISIBLE);
                    } else {
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                    spansManager.setData(et_edit.getText().toString(), editText, id);
                    //如果当前span身上有值，先赋值给et身上
                /*editText.setText(TextUtils.isEmpty(spansManager.mSpans.get(id).mText)?"":spansManager.mSpans.get(id).mText);
                editText.setSelection(spansManager.mSpans.get(id).mText.length());*/
                    //通过rf计算出et当前应该显示的位置
                /*RectF rf = spansManager.drawSpanRect(span);
                //设置EditText填空题中的相对位置
                spansManager.setEtXY(rf);
                spansManager.setSpanChecked(id);*/
                }
            });

            WindowManager.LayoutParams params = window.getAttributes();
            params.width = (int) (((Activity) context).getWindowManager().getDefaultDisplay().getWidth() * 0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }

    public static void showScore(Context context, EditText editText, GradeQuestionBankVo gradeQuestionBankVo){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000) {
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edit_score, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            tv_title.setText("扣分");
            et_edit.setText(editText.getText().toString());
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if (!et_edit.getText().toString().equals("")) {
                iv_clean.setVisibility(View.VISIBLE);
            }
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (!s.toString().equals("")) {
                        iv_clean.setVisibility(View.VISIBLE);
                    } else {
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (et_edit.getText().toString().trim().equals("")) {
                        et_edit.setText("0");
                    }
                    if (Integer.valueOf(et_edit.getText().toString()) < 0) {
                        CustomToast.showText(context, "扣分不能为负数!", 3000, 0, 0).show();
                    } else if (Integer.valueOf(et_edit.getText().toString()) > gradeQuestionBankVo.getScore()) {
                        CustomToast.showText(context, "扣分不能大于该项总分!", 3000, 0, 0).show();
                    } else {
                        _alertDialog.dismiss();
                        editText.setText(et_edit.getText().toString());
                        gradeQuestionBankVo.setActualScore(Integer.valueOf(editText.getText().toString()));
                    }
                }
            });
            WindowManager.LayoutParams params = window.getAttributes();
            params.width = (int) (((Activity) context).getWindowManager().getDefaultDisplay().getWidth() * 0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }


    public static void showCertificateDialog2(Context context, String title, EditText editText,RadioButton radioButton1, RadioButton radioButton2){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000) {
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edittext, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            et_edit.setText(editText.getText().toString());
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if (!et_edit.getText().toString().equals("")) {
                iv_clean.setVisibility(View.VISIBLE);
            }
            tv_title.setText(title);
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (!s.toString().equals("")) {
                        iv_clean.setVisibility(View.VISIBLE);
                    } else {
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (et_edit.getText().toString().trim().length() == 18) {
                        String number = et_edit.getText().toString().trim();
                        String message = IDCardUtil.IDCardValidate(number);
                        if ("1".equals(message)) {
                            if ((Integer.valueOf(number.substring(16, 17)) % 2) == 0) {
                                radioButton2.setChecked(true);
                            } else {
                                radioButton1.setChecked(true);
                            }
//                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
//                            Date date = new Date();
//                            String year = sdf.format(date);
//                            age.setText(String.valueOf(Integer.valueOf(year) - Integer.valueOf(number.substring(6, 10))));
                            _alertDialog.dismiss();
                            editText.setText(et_edit.getText().toString().trim());
                        } else {
                            CustomToast.showText(context, message, 3000, 0, 0).show();
                        }
                    } else {
                        //radioGroup.clearCheck(); age.setText("");
                        CustomToast.showText(context, "身份证长度不为18", 3000, 0, 0).show();
                    }
                }
            });


            WindowManager.LayoutParams params = window.getAttributes();
            params.width = (int) (((Activity) context).getWindowManager().getDefaultDisplay().getWidth() * 0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }

    public static void showCertificateDialog(Context context, String title, EditText editText,RadioGroup radioGroup,RadioButton radioButton1, RadioButton radioButton2, EditText age){
        long now = System.currentTimeMillis();
        if(now - lastClickTime>1000) {
            lastClickTime = now;
            LayoutInflater mLayoutInflater = LayoutInflater.from(context);
            View view = mLayoutInflater.inflate(R.layout.dialog_edittext, null);
            final AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context, R.style.ActionSheetDialogStyle);
            alertBuilder.setView(view);
            _alertDialog = alertBuilder.create();
            //获取当前Activity所在的窗体
            Window window = _alertDialog.getWindow();
            window.setGravity(Gravity.CENTER);
            _alertDialog.show();
            EditText et_edit = (EditText) view.findViewById(R.id.et_edit);
            ImageView iv_cancel = (ImageView) view.findViewById(R.id.iv_cancel);
            ImageView iv_clean = (ImageView) view.findViewById(R.id.iv_clean);
            TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
            Button btn_confirm = (Button) view.findViewById(R.id.btn_confirm);
            et_edit.setText(editText.getText().toString());
            et_edit.setFocusable(true);
            et_edit.setFocusableInTouchMode(true);
            et_edit.requestFocus();
            if (!et_edit.getText().toString().equals("")) {
                iv_clean.setVisibility(View.VISIBLE);
            }
            tv_title.setText(title);
            iv_cancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    _alertDialog.dismiss();
                }
            });
            iv_clean.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    et_edit.setText("");
                    iv_clean.setVisibility(View.GONE);
                }
            });
            et_edit.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (!s.toString().equals("")) {
                        iv_clean.setVisibility(View.VISIBLE);
                    } else {
                        iv_clean.setVisibility(View.GONE);
                    }
                }
            });
            btn_confirm.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (et_edit.getText().toString().trim().length() == 18) {
                        String number = et_edit.getText().toString().trim();
                        String message = IDCardUtil.IDCardValidate(number);
                        if ("1".equals(message)) {
                            if ((Integer.valueOf(number.substring(16, 17)) % 2) == 0) {
                                radioButton2.setChecked(true);
                            } else {
                                radioButton1.setChecked(true);
                            }
                            SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
                            Date date = new Date();
                            String year = sdf.format(date);
                            age.setText(String.valueOf(Integer.valueOf(year) - Integer.valueOf(number.substring(6, 10))));
                            _alertDialog.dismiss();
                            editText.setText(et_edit.getText().toString().trim());
                        } else {
                            CustomToast.showText(context, message, 3000, 0, 0).show();
                        }
                    } else {
                        //radioGroup.clearCheck(); age.setText("");
                        CustomToast.showText(context, "身份证长度不为18", 3000, 0, 0).show();
                    }
                }
            });


            WindowManager.LayoutParams params = window.getAttributes();
            params.width = (int) (((Activity) context).getWindowManager().getDefaultDisplay().getWidth() * 0.9);                     //使用这种方式更改了dialog的框宽
            window.setAttributes(params);
        }
    }
}
